﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ExtAspNet;
using Manager;
using Model;
using Manager.CustomerHelper;
namespace HealthSystem
{
    public partial class CtityCenterAdmin : BasePage
    {
        HW_Manger_Admin_UserManager manager = new HW_Manger_Admin_UserManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.CityCenterAdmin;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Initialize();
            if (!IsPostBack)
            {
                BindGrid();
            }
            
        }
        public void BindGrid()
        {
            //string parentDistrictId = CustomerProfile.ParentDistrictId;
            DataTable list = manager.GetAdminByRole(1011);
            this.Gird1.DataSource = list;
            this.Gird1.DataBind();
        }
        public void Grid1_DoubleClick(object sender, ExtAspNet.GridRowClickEventArgs e)
        {
            int index = e.RowIndex;
            string pid = this.Gird1.Rows[index].DataKeys[0].ToString();
            string name = Gird1.Rows[index].DataKeys[1].ToString();
            PageContext.RegisterStartupScript(Window1.GetShowReference("DistrictCenterAdmin.aspx?pid=" + pid, name));
        }
        public void Window1_Close(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            try
            {
                string username = Gird1.Rows[e.RowIndex].DataKeys[1].ToString();
                if (e.CommandName == "reset")
                {
                    //重置密码
                    HW_Manger_Admin_UserManager adminUserManager = new HW_Manger_Admin_UserManager();
                    //HW_OrgUserManager orgUserManager = new HW_OrgUserManager();
                    //HW_Manger_Admin_User managerUser = adminUserManager.GetById(username);
                    string pass = System.Configuration.ConfigurationManager.AppSettings["default"].ToString();
                    adminUserManager.ResetPassWord(username, pass);
                    Alert.Show("密码重置成功");
                    //BindGrid();
                }
            }
            catch
            {
                Alert.Show("操作失败!");
            }
        }
        public void Initialize()
        {
            if (CustomerProfile.RoleId == 1001)
            {
                ExtAspNet.LinkButtonField link = new LinkButtonField();
                link.HeaderText = "重置密码";
                link.Text = "重置密码";
                link.CommandName = "reset";
                link.ConfirmText = "你确定要重置密码";
                Gird1.Columns.Add(link);

                ExtAspNet.WindowField winfiled = new WindowField();
                winfiled.WindowID = "Window1";
                winfiled.HeaderText = "修改保健所管理员";
                winfiled.Icon = ExtAspNet.Icon.Pencil;
                winfiled.DataIFrameUrlFields = "XX_UserName";
                winfiled.DataIFrameUrlFormatString = "Cityadmin_Edit.aspx?id={0}";
                winfiled.DataWindowTitleField = "XX_UserName";
                winfiled.DataWindowTitleFormatString = "编辑 - {0}";
                Gird1.Columns.Add(winfiled);
            }
        }
    }
}